<template>
	<view>
		<scroll-view @tap="scroll" :scroll-top="scrollTop" scroll-y="true" style="position:absolute; top:0; left:0; right:0; bottom:0;">
			<view class="container" v-if="detail.goods_id">
				<view class="swiper">
					<swiper :autoplay="autoplay" @change="setCurrent" class="banner-box  swiper-box" :duration="duration"
					 :indicator-dots="indicatorDots" :interval="interval" circular="true">
						<swiper-item v-for="(item,index) in detail.image" :key="index" @tap="onPreviewImages" :data-index="index">
							<image class="slide-image" mode="aspectFill" :src="item.file_path"></image>
						</swiper-item>
					</swiper>
					<view class="banner-num">
						<text>{{currentIndex}}</text>
						<text>/{{detail.image.length}}</text>
					</view>
				</view>

				<!-- 团购提醒 -->
				<view class="goods-attention dis-flex flex-y-center">
					<!-- 商品价格 -->
					<view class="goods-price">
						<text class="price-currency f-26">￥</text>
						<text class="price-text">{{ sharing_price }}</text>
					</view>
					<view class="goods-message">
						<view class="line-price" v-if="line_price > 0">
							<text class="f-22">￥</text>
							<text class="f-26">{{ line_price }}</text>
						</view>
						<view class="dis-flex flex-y-center">
							<view class="in-tag f-24">团购中</view>
							<view class="in-txt f-24">
								<text></text>{{ detail.goods_sales }}人已参团</view>
						</view>
					</view>
				</view>

				<view class="goods-name b-f">
					<!-- 商品名称 -->
					<view class="dis-flex flex-y-center">
						<view class="flex-box dis-flex flex-dir-column">
							<view class="goods-title">
								<view class="title f-30 twolist-hidden">
									<text class="col-m f-28"> [{{ detail.people }}人团] </text>
									<text>{{ detail.goods_name }}</text>
								</view>
							</view>
						</view>
						<!-- 分享按钮 -->
						<view class="goods__share">
							<form @submit="onClickShare" report-submit="true">
								<button form-type="submit" class="btn-normal dis-flex flex-dir-column">
									<text class="share__icon iconfont icon-fenxiang"></text>
									<text class="f-24">分享</text>
								</button>
							</form>
						</view>
					</view>
					<!-- 商品卖点 -->
					<view class="goods-selling-point">
						<text class="f-24">{{ detail.selling_point }}</text>
					</view>
				</view>

				<!-- 选择商品规格 -->
				<form v-if="goodsMultiSpec.spec_attr" @submit="onToggleTrade" report-submit>
					<button class="btn-normal" form-type="submit">
						<view class="sku-selector cont-box b-f m-top20 dis-flex flex-y-center">
							<view class="flex-box f-28">
								<text class="col-9">选择：</text>
								<text v-for="(item,index) in goodsMultiSpec.spec_attr" :key="index"> {{item.group_name }} </text>
							</view>
							<view class="flex-box f-26 col-9 t-r">
								<text class="iconfont icon-xiangyoujiantou"></text>
							</view>
						</view>
					</button>
				</form>

				<!-- 商品评价 -->
				<view class="goods-comment" v-if="detail.comment_data.length ">
					<view class="cont-box b-f goods-property-box m-top20">
						<text class="col-3 f-30">评价 ( detail.comment_data_count }}条)</text>
						<text @tap="navigateToComment" class="comment-num">查看更多</text>
						<view class="goods-property-jianTou">
							<text class="iconfont icon-xiangyoujiantou user-orderJtou" style="margin-top:0;"></text>
						</view>
					</view>
					<view class="goods-comment-box b-f" v-for="(item,index) in detail.comment_data" :key="index">
						<view class="cont-box goods-comment-box b-t b-f b-b">
							<view class="dis-flex">
								<view class="user">
									<text class="user_name f-26"> {{item.user.nickName }}</text>
								</view>
								<view class="com_xing">
									<text class="iconfont icon-shoucang active"></text>
									<block v-if=" item.score < 30 ">
										<text class="iconfont icon-shoucang active"></text>
										<text class="iconfont icon-shoucang active"></text>
									</block>
									<block v-if=" item.score < 20 ">
										<text class="iconfont icon-shoucang active"></text>
										<text class="iconfont icon-shoucang active"></text>
									</block>
								</view>
							</view>
							<view class="goods-comment-cont m-top20">
								<text class="f-26 twolist-hidden"> {{ item.content }}</text>
							</view>
							<view class="f-22 col-9 m-top10"> {{ item.create_time }}</view>
						</view>
					</view>
				</view>

				<!-- 进行中的团购 -->
				<view class="top-nav-bar m-top20 b-f" v-if="activeList.length">
					<view class="top-nav dis-flex flex-x-between">
						<text>进行中的团购</text>
						<!-- <text class="col-9">更多团购 <text class="iconfont icon-xiangyoujiantou"></text> </text> -->
					</view>
					<!-- 进行中的团购-内容部分 -->
					<view class="corwd" v-for="(item,index) in activeList" :key="index" @tap="onTargetActive" :data-id="item.active_id">
						<view class="corwd_people">
							<!-- 进行中的团购-头像 -->
							<view class="">
								<image :src="item.user.avatarUrl" class="corwd_people_images"></image>
							</view>
							<!-- 进行中的团购-名称 -->
							<text class="onelist-hidden">{{ item.user.nickName }}的团</text>
						</view>
						<view class="corwd_time">
							<view class="corwd_time_text">
								<!-- 进行中的团购-开团人数 -->
								<text class="corwd_time_title onelist-hidden">还差<text>{{ item.people - item.actual_people }}</text>人成团</text>
								<!-- 进行中的团购-倒计时 -->
								<text class="corwd_time_number col-9 onelist-hidden">剩余{{ countDownList[index].day }}天{{ countDownList[index].hou }}:{{ countDownList[index].min }}:{{ countDownList[index].sec }}</text>
							</view>
							<!-- 进行中的团购-按钮 -->
							<button>去参团</button>
						</view>
					</view>
				</view>

				<!-- 拼团玩法 -->
				<view class="rule-nav top-nav-bar m-top20 b-f">
					<form @submit="onToggleRules" report-submit="true">
						<button form-type="submit" class="btn-normal">
							<view class="top-nav dis-flex flex-x-between">
								<text>拼团玩法</text>
								<text class="f-25 col-9">查看规则</text>
							</view>
							<!-- 拼团步骤 -->
							<view class="rule-simple dis-flex flex-x-around">
								<view class="simple-item dis-flex flex-dir-column flex-y-center">
									<view class="i-number dis-flex flex-x-center flex-y-center">
										<text class="f-30">1</text>
									</view>
									<view class="i-text f-28">选择商品</view>
								</view>
								<view class="simple-item dis-flex flex-dir-column flex-y-center">
									<view class="i-number dis-flex flex-x-center flex-y-center">
										<text class="f-30">2</text>
									</view>
									<view class="i-text f-28">开团/参团</view>
								</view>
								<view class="simple-item dis-flex flex-dir-column flex-y-center">
									<view class="i-number dis-flex flex-x-center flex-y-center">
										<text class="f-30">3</text>
									</view>
									<view class="i-text f-28">邀请好友</view>
								</view>
								<view class="simple-item dis-flex flex-dir-column flex-y-center">
									<view class="i-number dis-flex flex-x-center flex-y-center">
										<text class="f-30">4</text>
									</view>
									<view class="i-text f-28">人满成团</view>
								</view>
							</view>
						</button>
					</form>
				</view>

				<!-- 商品描述 -->
				<view class="p-bottom" style="background: #FFFFFE;padding: 0 10upx;margin-bottom: 47px;">
					<view class="top-nav m-top20 b-f b-b">
						<view class="top-nav-bar">商品描述</view>
					</view>
					<view class="order" :hidden="hiddenOrder">
						<view v-if="detail.content!=''">
							<view class="b-f goods-detail-box">
								<view class="goods-cont-li">
									<rich-text :nodes="article"></rich-text>
								</view>
							</view>
						</view>
						<view v-else>
							<view class="yoshop-notcont">
								<text class="iconfont icon-wushuju"></text>
								<text class="cont">亲,此处暂无详情数据</text>
							</view>
						</view>
					</view>
				</view>

				<!-- 底部操作栏 -->
				<view class="footer-fixed f-28">
					<!-- 返回主页 -->
					<form @submit="onNavigationHome" report-submit="true">
						<button form-type="submit" class="btn-normal">
							<view class="goods-fixed-icon dis-flex flex-x-center flex-y-center">
								<text class="iconfont icon-zhuye"></text>
							</view>
						</button>
					</form>
					<!-- 在线客服 -->
					<!-- #ifdef MP-WEIXIN -->
					<view class="goods-fixed-icon dis-flex flex-x-center flex-y-center">
						<button open-type="contact" sessionFrom="weapp" size="27" style="opacity: 0;position:absolute;top:0px;left:0px;display:block;width:100%;height:100%;"
						 type="default-light"></button>
						<text class="iconfont icon-kefu "></text>
					</view>
					<!-- #endif -->

					<!-- #ifdef APP-PLUS || H5-->
					<view class="goods-fixed-icon dis-flex flex-x-center flex-y-center">
						<button  size="27" style="opacity: 0;position:absolute;top:0px;left:0px;display:block;width:100%;height:100%;"
						 type="default-light" @tap="openkefu"></button>
						<text class="iconfont icon-kefu "></text>
					</view>
					<!-- #endif -->
					<!-- 购买按钮 -->
					<view class="fixed-buttons flex-box dis-flex">
						<view v-if="detail.is_alone == 0" class="order-number flex-box dis-flex flex-dir-column flex-x-center">
							<form @submit="onTriggerOrder" report-submit="true" data-type="10">
								<button form-type="submit" class="btn-normal">
									<view class="f-26">￥{{ goods_price }}</view>
									<view>单独购买</view>
								</button>
							</form>
						</view>
						<view class="order-bt flex-box dis-flex flex-dir-column flex-x-center">
							<form @submit="onTriggerOrder" report-submit="true" data-type="20">
								<button form-type="submit" class="btn-normal col-f">
									<view class="f-26">￥{{ sharing_price }}</view>
									<view>发起拼单</view>
								</button>
							</form>
						</view>
					</view>
				</view>
			</view>
		</scroll-view>

		<!-- 确认购买弹窗 -->
		<view class="pop pop--bottom" :class="[showBottomPopup ? 'pop--show' : '']" @close="onToggleTrade">
			<view class="pop__mask " ></view>
			<view class="pop__container pop_querenshop">
				<view class="popup__trade">
					<!-- 关闭按钮 -->
					<view class="trade-close dis-flex flex-x-center flex-y-center">
						<form @submit="onToggleTrade" report-submit="true">
							<button form-type="submit" class="btn-normal">
								<text class="iconfont icon-close f-26"></text>
							</button>
						</form>
					</view>
					<!-- 主体信息 -->
					<view class="trade-main">
						<view class="goods-info dis-flex">
							<!-- 图片名称 -->
							<view class="goods-image" @tap="onPreviewSkuImage">
								<image :src="skuCoverImage"></image>
							</view>
							<view class="right flex-box">
								<view class="money-box dis-flex flex-y-end">
									<!-- 商品价 -->
									<view class="goods-price">
										<text class="col-m f-26">￥</text>
										<text class="goods-price_num col-m f-40">{{ order_type == 10 ? goods_price : sharing_price }}</text>
									</view>
									<!-- 划线价 -->
									<view class="line-price" v-if="line_price > 0">
										<text>￥{{ line_price }}</text>
									</view>
								</view>
								<view class="goods-stock dis-flex">
									<text class="flex-box f-26 col-7">库存：{{stock_num}}</text>
								</view>
							</view>
						</view>
						<!-- 规格列表 -->
						<view class="goods-list-box" scroll-y="true" v-if="goodsMultiSpec.spec_attr">
							<view class="cf tmall-types" v-for="(attr,attr_idx) in goodsMultiSpec.spec_attr" :key="attr_idx">
								<view class="tipstxt" :data-id="attr.group_id">{{attr.group_name}}</view>
								<view class="cf cartypelist" v-for="(item,item_idx) in attr.spec_items" :key="item_idx">
									<view>
										<view @tap="onSwitchSpec(attr_idx,item_idx)" report-submit="true" :data-attr-idx="attr_idx" :data-item-idx="item_idx">
											<button form-type="submit" class="btn-normal">
												<view class="cartypeitem" :class="[ item.checked ? 'cur' : '' ]">{{item.spec_value}}</view>
											</button>
										</view>
									</view>
								</view>
							</view>
						</view>

						<!-- 购买数量 -->
						<view class="buy_number">
							<view class="buy-number f-26">
								<text>购买数量</text>
							</view>
							<view class="selectNumber">
								<form @submit="onDecGoodsNumber" report-submit="true">
									<button form-type="submit" class="default" :class="goods_num>1?'':'disabled'" type="default">-</button>
								</form>
								<input @input="onInputGoodsNum" type="number" :value=" goods_num "></input>
								<form @submit="onIncGoodsNumber" report-submit="true">
									<button form-type="submit" class="default" type="default">+</button>
								</form>
							</view>
						</view>
					</view>
					<!-- 底部操作栏 -->
					<view class="footer-fixed f-30">
						<block v-if="stock_num > 0">
							<view class="order-bt dis-flex flex-x-center flex-y-center" @tap="onCheckout" data-type="buyNow">
								<text>确定</text>
							</view>
						</block>
						<view class="default-btn" v-else>暂无现货</view>
					</view>
				</view>
			</view>
		</view>

		<!-- 返回顶部 -->
		<view class="widget-goTop" v-if="floorstatus">
			<form @submit="onScrollTop" report-submit="true">
				<button form-type="submit" class="btn-normal">
					<text class="iconfont icon-fanhuidingbu"></text>
				</button>
			</form>
		</view>


		<!-- 分享按钮 -->
		<zanactionsheet :show="share.show" :actions="share.actions" :cancelText="share.cancelText" :cancelWithMask="share.cancelWithMask"
		 @cancel="closeActionSheet" @actionclick="clickAction" mask-class="tiny" :goods_name="detail.goods_name" />


		<!-- 商品海报 弹出层 -->
		<!-- <zanpopup :show="share.showPopup" @close="togglePopup"> -->
		<view class="pop pop--bottom" :class="[share.showPopup ? 'pop--show' : '']" @close="onTogglePopup">
			<view class="pop__mask" @tap="onTogglePopup"></view>

			<view class="pop-poster pop-example__container pop__container">
				<!-- 关闭按钮 -->
				<view class="pop-close dis-flex flex-x-center flex-y-center" @tap="onTogglePopup">
					<text class="iconfont icon-shanchu f-30 col-9"></text>
				</view>
				<form @submit="onSavePoster" report-submit="true">
					<view class="poster__image">
						<image mode="widthFix" :src="qrcode"></image>
					</view>
					<view class="poster__tips m-top10 t-c">
					</view>
					<view class="padding-box m-top10 profile-btn">
						<button form-type="submit">保存图片</button>
					</view>
				</form>
			</view>
		</view>
		<!-- </zanpopup> -->


		<xy-dialog title="拼团规则" content="" :show="dialogshow" 
		 :isShowCancel="!dialogshow" confirmColor="#df5000">
			<view style="padding: 0 30upx 30upx;text-align:left;">
				<view v-for="(items,indexs) in rule_detail" :key='indexs' style="margin: 20upx 0upx;">
					{{items}}
				</view>
			</view>
		</xy-dialog>

		<!-- 快捷导航 -->
		<shortcut id=""></shortcut>
	</view>
</template>

<script>
	import zanactionsheet from '../../../components/goods/actionsheet.vue'
	import zanpopup from '../../../components/goods/popup.vue'
	import shortcut from '../../../components/goods/shortcut.vue'
	// import zandialog from '../../../components/dialog/index.vue'
	import xyDialog from '@/components/xy-dialog/xy-dialog.vue';

	// 工具类
	const util = require('../../../utils/util.js');
	const Sharing = require('../../../utils/extend/sharing.js');
	// const Dialog = require('../../../components/dialog/dialog.js');
	export default {
		// const App = getApp();


		components: {
			// （组件命名）
			zanactionsheet,
			zanpopup,
			shortcut,
			// zandialog,
			xyDialog
		},
		props: {
			zanpopup: {},
			shortcut: {},
			zanactionsheet: {},
			// zandialog: {}
		},
		data() {
			return {
				dialogshow: false, //拼团规则是否显示
				rule_detail: {},
				hiddenOrder: null,
				indicatorDots: true, // 是否显示面板指示点c
				autoplay: true, // 是否自动切换
				interval: 3000, // 自动切换时间间隔
				duration: 800, // 滑动动画时长
				goodsMultiSpec: {},
				skuCoverImage: null,

				currentIndex: 1, // 轮播图指针
				floorstatus: false, // 返回顶部
				showView: true, // 显示商品规格

				detail: {}, // 商品详情信息
				sharing_price: 0, // 拼团价格
				goods_price: 0, // 单买价
				line_price: 0, // 划线价格
				stock_num: 0, // 库存数量

				order_type: 20, // 下单类型 10=>单独购买 20=>拼团
				goods_num: 1, // 商品数量
				goods_sku_id: 0, // 规格id
				cart_total_num: 0, // 购物车商品总数量c

				specData: {}, // 多规格信息
				c: '',
				scrollTop: '',
				showBottomPopup: null,
				image_path: '',
				qrcode: '',
				activeList: {},
				article: '',

				setting: {}, //拼团设置

				countDownList: [], // 时间记录
				actEndTimeList: [],
				// 分享按钮组件(待开发)
				share: {
					show: false,
					cancelWithMask: true,
					cancelText: '关闭',
					actions: [{
						name: '生成商品海报',
						className: 'action-class',
						loading: false
					}, {
						name: '发送给朋友',
						openType: 'share'
					}],
					// 商品海报
					showPopup: false,
				},
				// 记录规格的数组
				goods_spec_arr: [],
				goodsSpecArr:[]

			}
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(e) {
			let _this = this,
				scene = _this.getSceneData(e);
			// 商品id
			_this.goods_id = e.goods_id ? e.goods_id : scene.gid;
			// 获取商品信息
			_this.getGoodsDetail();
			// 获取拼团设置
			_this.getSetting();
		},
		methods: {
			/**
			 * app客服
			 */
			openkefu: function() {
				let url = 'mqqwpa://im/chat?chat_type=crm&uin=' + this.getQQkefu()
				this.openBrowser(url);
			},
			/**
			 * 获取场景值(scene)
			 */
			getSceneData: function(query) {
				return query.scene ? util.scene_decode(query.scene) : {};
			},

			/**
			 * 获取拼团设置
			 */
			getSetting() {
				let _this = this;
				_this._get('sharing.setting/getAll', {}, function(result) {
					_this.setData(
						result.data
					);
				});
			},

			/**
			 * 获取商品信息
			 */
			getGoodsDetail: function() {
				let _this = this;
				_this._get('sharing.goods/detail', {
					goods_id: _this.goods_id
				}, function(result) {

					// 初始化商品详情数据
					let data = _this._initGoodsDetailData(result.data);
					_this.setData(data);
					// // 执行倒计时函数
					_this.countDown();
				});
			},

			/**
			 * 初始化商品详情数据
			 */
			_initGoodsDetailData(data) {
				let _this = this;
				// 商品详情
				let goodsDetail = data.detail;
				// 富文本转码
				if (goodsDetail.content.length > 0) {
					let article = goodsDetail.content.replace(/<img/g, "<img style='max-width:100%;height:auto;'");
					_this.setData({
						'article': article
					});
				}
				// 商品价格/划线价/库存
				data.goods_sku_id = goodsDetail.goods_sku.spec_sku_id;
				data.goods_price = goodsDetail.goods_sku.goods_price;
				data.sharing_price = goodsDetail.goods_sku.sharing_price;
				data.line_price = goodsDetail.goods_sku.line_price;
				data.stock_num = goodsDetail.goods_sku.stock_num;
				// 商品封面图(确认弹窗)
				data.skuCoverImage = goodsDetail.goods_image;
				// 多规格商品封面图(确认弹窗)
				if (goodsDetail.spec_type == 20 && goodsDetail.goods_sku['image']) {
					data.skuCoverImage = goodsDetail.goods_sku['image']['file_path'];
				}
				// 初始化商品多规格
				if (goodsDetail.spec_type == 20) {
					data.goodsMultiSpec = _this.initManySpecData(goodsDetail.goods_multi_spec);
				}
				console.log(data.goodsMultiSpec)
				// 记录倒计时时间
				data['actEndTimeList'] = [];
				if (data.activeList.length > 0) {
					data.activeList.forEach(item => {
						data['actEndTimeList'].push(item.end_time.text);
					});
				}
				return data;
			},

			/**
			 * 初始化商品多规格
			 */
			initManySpecData(data) {
				this.goodsSpecArr = [];
				for (let i in data.spec_attr) {
					for (let j in data.spec_attr[i].spec_items) {
						if (j < 1) {
							data.spec_attr[i].spec_items[0].checked = true;
							this.goodsSpecArr[i] = data.spec_attr[i].spec_items[0].item_id;
						}
					}
				}
				return data;
			},

			/**
			 * 点击切换不同规格
			 */
			onSwitchSpec(attr_idx,item_idx) {
				
				let _this = this,
					attrIdx = attr_idx,
					itemIdx = item_idx,
					goodsMultiSpec = _this.goodsMultiSpec;

				for (let i in goodsMultiSpec.spec_attr) {
					for (let j in goodsMultiSpec.spec_attr[i].spec_items) {
						if (attrIdx == i) {
							goodsMultiSpec.spec_attr[i].spec_items[j].checked = false;
							if (itemIdx == j) {
								goodsMultiSpec.spec_attr[i].spec_items[itemIdx].checked = true;
								this.goodsSpecArr[i] = goodsMultiSpec.spec_attr[i].spec_items[itemIdx].item_id;
							}
						}
					}
				}
				_this.setData({
					goodsMultiSpec
				});
				// 更新商品规格信息
				_this._updateSpecGoods();
			},

			/**
			 * 更新商品规格信息
			 */
			_updateSpecGoods: function() {
				let _this = this,
					specSkuId = this.goodsSpecArr.join('_');
				// 查找skuItem
				let spec_list = _this.goodsMultiSpec.spec_list,
					skuItem = spec_list.find((val) => {
						return val.spec_sku_id == specSkuId;
					});

				console.log(skuItem)
				// 记录goods_sku_id
				// 更新商品价格、划线价、库存
				if (typeof skuItem === 'object') {
					_this.setData({
						goods_sku_id: skuItem.spec_sku_id,
						goods_price: skuItem.form.goods_price,
						sharing_price: skuItem.form.sharing_price,
						line_price: skuItem.form.line_price,
						stock_num: skuItem.form.stock_num,
						image_path: skuItem.form.image_id > 0 ? skuItem.form.image_path : this.detail.goods_image
					});
				}
			},

			/**
			 * 设置轮播图当前指针 数字
			 */
			setCurrent: function(e) {
				this.setData({
					currentIndex: e.detail.current + 1
				});
			},

			/**
			 * 返回顶部
			 */
			onScrollTop: function(e) {

				this.saveFormId(e.detail.formId);
				this.setData({
					scrollTop: 0
				});
			},

			/**
			 * 显示/隐藏 返回顶部按钮
			 */
			scroll: function(e) {
				this.setData({
					floorstatus: e.detail.scrollTop > 200
				})
			},

			/**
			 * 增加商品数量
			 */
			onIncGoodsNumber: function(e) {
				let _this = this;
				_this.saveFormId(e.detail.formId);
				_this.setData({
					goods_num: ++this.goods_num
				})
			},

			/**
			 * 减少商品数量
			 */
			onDecGoodsNumber: function(e) {
				let _this = this;
				_this.saveFormId(e.detail.formId);
				if (_this.goods_num > 1) {
					_this.setData({
						goods_num: --_this.goods_num
					});
				}
			},
			/**
			 * 自定义输入商品数量
			 */
			onInputGoodsNum(e) {
				let _this = this,
					iptValue = e.detail.value;
				if (!util.isPositiveInteger(iptValue) && iptValue !== '') {
					iptValue = 1;
				}
				_this.setData({
					goods_num: iptValue
				});
			},

			/**
			 * 加入购物车and立即购买
			 */
			onCheckout: function(e) {
				let _this = this;
				// 表单验证
				if (!_this._onVerify()) {
					return false;
				}
				// 立即购买
				uni.navigateTo({
					url: '../checkout/checkout?' + _this.urlEncode({
						order_type: _this.order_type,
						goods_id: _this.goods_id,
						goods_num: _this.goods_num,
						goods_sku_id: _this.goods_sku_id,
					}),
					success() {
						// 关闭弹窗
						_this.onToggleTrade();
					}
				});

			},
			/**
			 * 表单验证
			 */
			_onVerify() {
				let _this = this;
				if (_this.goods_num === '') {
					_this.showError('请输入购买数量');
					return false;
				}
				// 将购买数量转为整型，防止出错
				_this.setData({
					goods_num: parseInt(_this.goods_num)
				});
				if (_this.goods_num <= 0) {
					_this.showError('购买数量不能为0');
					return false;
				}
				return true;
			},

			/**
			 * 浏览商品图片
			 */
			onPreviewImages: function(e) {
				let _this = this;
				let index = e.currentTarget.dataset.index,
					imageUrls = [];
				_this.detail.image.forEach(item => {
					imageUrls.push(item.file_path);
				});
				uni.previewImage({
					current: imageUrls[index],
					urls: imageUrls
				})
			},


			/**
			 * 预览Sku规格图片
			 */
			previewSkuImage: function(e) {
				uni.previewImage({
					current: this.image_path,
					urls: [this.image_path]
				})
			},

			/**
			 * 跳转到评论
			 */
			navigateToComment: function(e) {
				let _this = this;
				_this.saveFormId(e.detail.formId);
				uni.navigateTo({
					url: './comment/comment?goods_id=' + this.goods_id
				})
			},



			/**
			 * 分享当前页面
			 */
			onShareAppMessage: function() {

				let _this = this;
				// 构建页面参数
				let params = _this.urlEncode({
					'goods_id': _this.goods_id,
					'referee_id': _this.getUserId()
				});
				return {
					title: _this.detail.goods_name,
					desc: "",
					path: "/pages/sharing/goods/index?" + params
				};
			},


			/**
			 * 切换商品海报
			 */
			onTogglePopup() {
				let _this = this;
				_this.setData({
					'share.showPopup': !_this.share.showPopup
				});
			},
			/**
			 * 显示分享选项
			 */
			onClickShare(e) {
				let _this = this;
				// #ifdef APP-PLUS || H5
					uni.showActionSheet({
						itemList: ['生成商品海报', '发送给朋友'],
						success: function (res) {
							_this.toShare(res.tapIndex)
						},
					})
					return;
				// #endif
				this.setData({
					'share.show': true
				});
			},
			/* 
			* 用户点击了分享 
			 */
			toShare(e){
				let _this = this;
				if (e == 0) {//分享到海报
				
					let goodsinfo = {
						"goods_trueprice": _this.goods_price, 
						"goods_image": _this.detail.goods_image,
						"goods_name": _this.detail.goods_name,
						"goods_id": _this.detail.goods_id, 
					};
					uni.setStorageSync('goodsinfo', goodsinfo);
				
					uni.navigateTo({
						url:'../../../pages/poster/index?posterType=goods'
					})
				}else{//分享到微信
				// #ifdef APP-PLUS
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 0,
					href: uni.getStorageSync('versionInfo').url,
					title: _this.detail.goods_name,
					summary: _this.detail.goods_name,
					imageUrl: _this.detail.selling_point,
					success: function(res) {
						console.log("success:" + JSON.stringify(res));
					},
					fail: function(err) {
						console.log("fail:" + JSON.stringify(err));
					}
				});
				// #endif
				}
			},
			/**
			 * 关闭分享选项
			 */
			onCloseShare() {
				let _this = this;
				_this.setData({
					'share.show': false
				});
			},

			/**
			 * 点击生成商品海报
			 */
			onClickShareItem(e) {
				let _this = this;
				// if (e.detail.index === 0) {
				// 显示商品海报
				_this._showPoster();
				// }
				_this.onCloseShare();
			},


			/**
			 * 显示商品海报图
			 */
			_showPoster() {
				let _this = this;
				uni.showLoading({
					title: '加载中',
				});

				_this._get('sharing.goods/poster', {
					goods_id: _this.goods_id
				}, (result) => {
					console.log(result);
					_this.setData(result.data);
					_this.onTogglePopup();
				}, null, () => {
					uni.hideLoading();
				});
			},

			/**
			 * 保存海报图片
			 */
			onSavePoster: function(e) {
				let _this = this;
				// 记录formId
				// _this.saveFormId(e.detail.formId);
				uni.showLoading({
					title: '加载中',
				});
				// 下载海报图片
				uni.downloadFile({
					url: _this.qrcode,
					success: function(res) {
						uni.hideLoading();
						// 图片保存到本地
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success: function(data) {
								uni.showToast({
									title: '保存成功',
									icon: 'success',
									duration: 2000
								});
								// 关闭商品海报
								_this.onTogglePopup();
							},
							fail: function(err) {
								console.log(err.errMsg);
								if (err.errMsg === 'saveImageToPhotosAlbum:fail auth deny') {
									uni.showToast({
										title: "请允许访问相册后重试",
										icon: "none",
										duration: 1000
									});
									// #ifndef APP-PLUS
									setTimeout(function() {
										uni.openSetting();
									}, 1000);
									// #endif
								}
							},
							complete(res) {
								console.log('complete');
								// uni.hideLoading();
							}
						})
					}
				})
			},

			/**
			 * 确认购买弹窗
			 */
			onToggleTrade(e) {

				let _this = this;
				if (typeof e === 'object') {
					// 记录formId
					e.detail.hasOwnProperty('formId') && _this.saveFormId(e.detail.formId);
				}
				_this.setData({
					showBottomPopup: !_this.showBottomPopup
				});
			},

			/**
			 * 显示拼团规则
			 */
			onToggleRules: function(e) {

				let _this = this;

				var str = _this.setting.basic.rule_detail;
				var rule_detail = str.split(";");

				_this.setData({
					dialogshow: !_this.dialogshow,
					rule_detail: rule_detail,
				});
				return false;

				// uni-app未知原因无法使用自定义Dialog组件
				// 记录formId
				_this.saveFormId(e.detail.formId);
				// 显示拼团规则
				Dialog({
					title: '拼团规则',
					message: _this.setting.basic.rule_detail,
					selector: '#zan-base-dialog',
					buttons: [{
						text: '关闭',
						color: 'red',
						type: 'cash'
					}]
				});
			},

			/**
			 * 返回主页
			 */
			onNavigationHome: function(e) {
				this.saveFormId(e.detail.formId);
				uni.switchTab({
					url: '../../index/index',
				})
			},

			/**
			 * 立即下单
			 */
			onTriggerOrder: function(e) {
				// console.log(_this.saveFormId(e.detail.formId))
				let _this = this;
				// 设置当前购买类型
				_this.setData({
					order_type: e.currentTarget.dataset.type
				});
				_this.onToggleTrade();
			},
			/**
			 * 小于10的格式化函数
			 */
			timeFormat(param) {
				return param < 10 ? '0' + param : param;
			},

			/**
			 * 倒计时函数
			 */
			countDown() {
				// 获取当前时间，同时得到活动结束时间数组
				let newTime = new Date().getTime();
				let endTimeList = this.actEndTimeList;
				let countDownArr = [];

				// 对结束时间进行处理渲染到页面
				endTimeList.forEach(o => {
					let endTime = new Date(util.format_date(o)).getTime();
					let obj = null;
					// 如果活动未结束，对时间进行处理
					if (endTime - newTime > 0) {
						let time = (endTime - newTime) / 1000;
						// 获取天、时、分、秒
						let day = parseInt(time / (60 * 60 * 24));
						let hou = parseInt(time % (60 * 60 * 24) / 3600);
						let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
						let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
						obj = {
							day: day,
							hou: this.timeFormat(hou),
							min: this.timeFormat(min),
							sec: this.timeFormat(sec)
						}
					} else {
						//活动已结束，全部设置为'00'
						obj = {
							day: '00',
							hou: '00',
							min: '00',
							sec: '00'
						}
					}
					countDownArr.push(obj);
				})
				// 渲染，然后每隔一秒执行一次倒计时函数
				this.setData({
					countDownList: countDownArr
				});
				setTimeout(this.countDown, 1000);
			},

			/**
			 * 跳转到拼单页面
			 */
			onTargetActive(e) {
				uni.navigateTo({
					url: '../active/index?active_id=' + e.currentTarget.dataset.id,
				})
			},
		}
	}
</script>

<style>
	.slide-image {
		background: #fff;
	}

	.banner-box {
		height: 750upx;
		/* border-bottom: 1upx solid #e4e4e4; */
	}

	.user-orderJtou {
		color: #999;
		font-size: 26upx;
		position: absolute;
		top: 50%;
		margin-top: -9upx;
	}

	/* 底部操作栏 */

	.footer-fixed .goods-fixed-icon {
		width: 100upx;
		background: #fff;
		margin: 0 auto;
		padding: 0 6upx;
		border-left: 1upx solid #eee;
		height: 92upx;
		position: relative;
	}

	.footer-fixed .goods-fixed-icon:first-child {
		border-left: none;
	}

	.footer-fixed .goods-fixed-icon image {
		width: 56upx;
		height: 56upx;
		display: block;
		position: absolute;
		left: 50%;
		margin-left: -28upx;
		top: 50%;
		margin-top: -26upx;
	}

	.footer-fixed .goods-fixed-icon text {
		color: #7a7e83;
		font-size: 48upx;
	}

	.footer-fixed .goods-fixed-icon .icon-shoucang {
		font-size: 40upx;
	}

	.footer-fixed .goods-fixed-icon .s_cont {
		color: #ff495e;
	}

	.footer-fixed .fixed-buttons {
		height: 100%;
	}

	.footer-fixed .fixed-buttons .order-bt {
		width: auto;
		line-height: unset;
		height: 100%;
	}

	.footer-fixed .fixed-buttons .order-number {
		height: 100%;
	}

	/* 商品标题 */

	.goods-title {
		overflow: hidden;
		padding: 0 0upx 0 0;
		color: #333;
	}

	/* 商品价格 */

	.money-box {
		margin: 10upx 0;
	}

	.money-box .goods-price .goods-price_num {
		font-size: 40upx;
	}

	.money-box .line-price {
		font-size: 24upx;
		color: #999;
		padding-top: 6upx;
		text-decoration: line-through;
		margin-left: 12upx;
	}

	/* 商品销量 */

	.goods-sales-box .stock {
		display: block;
		text-align: right;
	}

	/* 商品评论 */

	.goods-comment .goods-property-box {
		position: relative;
		padding: 12px;
	}

	.goods-comment .goods-property-jianTou {
		width: 52upx;
		position: absolute;
		right: 0;
		top: 50%;
		margin-top: -13upx;
	}

	.goods-comment .goods-property-jianTou image {
		height: 100%;
		width: 100%;
	}

	.goods-comment-box .comment_btn {
		width: 220upx;
		margin: 0 auto;
		padding: 20upx 0;
	}

	.goods-comment-box .comment_btn text {
		display: block;
		padding: 5upx 0;
		color: #ff495e;
		font-size: 26upx;
		text-align: center;
		border: 1px solid #ff495e;
		border-radius: 30upx;
	}

	/* banner计数 */

	.banner-num {
		position: absolute;
		right: 30upx;
		margin-top: -70upx;
		padding: 0 18upx;
		background: rgba(0, 0, 0, 0.3);
		border-radius: 50upx;
		color: #fff;
		font-size: 32upx;
	}

	.banner-num text:last-child {
		color: rgba(255, 255, 255, 0.6);
		font-size: 26upx;
	}

	.footer-fixed .order-number {
		background: #ff92ba;
		color: #fff;
		text-align: center;
	}

	.footer-fixed .order-number button {
		background: none;
		padding: 0;
		/* font-size: 34upx; */
		color: #fff;
		line-height: inherit;
		border-radius: 0;
		border: 0;
	}

	.footer-fixed .order-number button::after {
		content: " ";
		width: 0;
		height: 0;
		position: absolute;
		top: 0;
		left: 0;
		border: none;
		transform: scale(0);
		transform-origin: 0 0;
		box-sizing: border-box;
		border-radius: 0;
	}

	.footer-fixed .default-btn {
		width: 100%;
		background-color: #ccc;
		color: #fff;
		text-align: center;
		line-height: 92upx;
	}

	.footer-fixed .flow_num {
		background: #ff495e;
		position: absolute;
		right: 20upx;
		top: 10upx;
		border-radius: 30upx;
		height: 30upx;
		min-width: 30upx;
	}

	/* 商品详情 */

	.goods-detail-box {
		font-size: 28upx;
	}

	/* 评价次数 */

	.comment-num {
		position: absolute;
		right: 34px;
		top: 50%;
		margin-top: -20upx;
		font-size: 28upx;
		color: #333;
	}

	.top-nav-bar {
		padding: 24upx;
		font-size: 28upx;
		color: #333;
	}

	.goods-fixed-icon contact-button {
		display: block;
	}

	/* 商品分享 */

	.goods__share button.share-btn {
		line-height: normal;
		padding: 0 0 0 10upx;
		background: none;
		border-radius: 0;
		box-shadow: none;
		font-size: 8pt;
		border: none;
		color: #888;
	}

	.goods__share button.share-btn::after {
		border: none;
	}

	.goods__share .share__icon {
		font-size: 46upx;
		margin-bottom: 5upx;
	}

	/* 商品海报 弹出层 */

	.pop-poster {
		position: relative;
		background: #fff;
		padding: 42upx;
		border-radius: 10upx;
	}

	/* 关闭按钮 */

	.pop-poster .pop-close {
		position: absolute;
		width: 56upx;
		height: 56upx;
		background: #fff;
		border-radius: 50%;
		box-shadow: 0 0 25upx rgba(0, 0, 0, 0.15);
		right: -28upx;
		top: -28upx;
	}

	.pop-poster .pop-close text {
		display: block;
	}

	.pop-poster .poster__image {
		padding: 0 40upx;
	}

	.pop-poster .poster__image image {
		box-shadow: 0 0 25upx rgba(0, 0, 0, 0.15);
		width: 460upx;
		height: 696.746upx;
	}

	.pop-poster .profile-btn button {
		margin-bottom: 0;
	}

	/* sku选择器 */

	.sku-selector {
		padding: 30upx 20upx;
	}

	/* 确认购买弹窗 */

	.popup__trade {
		width: 750upx;
		position: relative;
		padding-bottom: 92upx;
		z-index: 999;
	}

	.popup__trade .trade-close {
		position: absolute;
		top: 20upx;
		right: 20upx;
		width: 50upx;
		height: 50upx;
	}

	.popup__trade .trade-main {
		background: #fff;
		box-sizing: border-box;
		padding: 24upx;
	}

	.popup__trade .footer-fixed {
		position: absolute;
	}

	.popup__trade .footer-fixed .order-bt {
		width: 100%;
		line-height: unset;
	}

	.popup__trade .trade-main .goods-info {
		margin-bottom: 10upx;
	}

	.popup__trade .trade-main .goods-info .goods-image {
		margin-top: -40px;
		margin-right: 20upx;
	}

	.popup__trade .trade-main .goods-info .goods-image image {
		width: 90px;
		height: 90px;
		border: 5upx solid #fff;
		box-shadow: 0 4upx 10upx rgba(220, 220, 220, 0.79);
	}

	.popup__trade .trade-main .goods-info .money-box {
		margin: 0;
	}

	.popup__trade .trade-main .goods-info .goods-stock {
		padding-left: 10upx;
	}

	.popup__trade .trade-main .buy_number {
		margin: 20upx 0;
		justify-content: space-between;
	}

	.popup__trade .trade-main .buy_number .buyNumber {
		color: #888;
		background: #fff;
		border-radius: 10upx;
		margin-bottom: 10upx;
	}

	/* 商品规格 */

	.goods-list-box .tmall-types.mb20 {
		margin-bottom: 20upx;
	}

	.goods-list-box .tmall-types .tipstxt {
		font-size: 26upx;
		color: #888;
		margin-bottom: 10upx;
	}

	.goods-list-box .tmall-types .cartypelist {
		display: inline-block;
	}

	.goods-list-box .tmall-types .cartypelist .cartypeitem {
		font-size: 26upx;
		height: 55upx;
		line-height: 55upx;
		padding: 0 30upx;
		margin: 0 20upx 20upx 0;
		border-radius: 8upx;
		color: #888;
		border: 1px solid #e6e6e6;
	}


	.goods-attr .group-item .spec-item {
		font-size: 26rpx;
		height: 55rpx;
		line-height: 55rpx;
		padding: 0 30rpx;
		margin: 0 20rpx 20rpx 0;
		border-radius: 8rpx;
		color: #888;
		border: 1rpx solid #e6e6e6;
	}

	.cur {
		background: #f82169;
		border: 1upx solid #f82169;
		color: #fff;
	}

	.goods-attr .group-item .spec-item.cur:after {
		position: absolute;
		bottom: 0;
		right: 0;
		content: '';
		display: inline-block;
		width: 16upx;
		height: 16upx;
	}

	.goods-attr .group-item .spec-item.disabled {
		color: #dedede;
		cursor: not-allowed;
		background: #eee;
		border: 2upx dashed #dedede;
	}

	.select-number {
		width: 202rpx;
		height: 52rpx;
		flex-direction: row;
		border: 1rpx solid rgb(231, 231, 231);
		border-radius: 5rpx;
	}

	.select-number .default {
		float: left;
		width: 60rpx;
		height: 52rpx;
		line-height: 48rpx;
		padding: 0;
		background: #fff;
		color: #444;
		font-size: 40rpx;
		border-radius: unset;
	}

	.select-number .disabled {
		background: #f7f7f7;
		color: #ddd;
	}

	.select-number button:after {
		content: none;
		border: none;
	}

	.select-number input {
		float: left;
		width: 80rpx;
		height: 52rpx;
		line-height: 52rpx;
		border-right: 1rpx solid #eee;
		border-left: 1rpx solid #eee;
		text-align: center;
		font-size: 28rpx;
		color: #444;
	}

	/* 团购提醒 */

	.goods__share {
		margin-left: 20upx;
	}

	.goods-name {
		padding: 26upx 20upx;
	}

	/* 商品卖点 */

	.goods-name .goods-selling-point {
		color: #f20c59;
	}

	.goods-attention {
		background: url("https://css.gomein.net.cn/plus/style/product/item/images/tq-bg.png?v=2017111401") center no-repeat;
		height: 108upx;
		color: #fff;
		font-size: 28upx;
		padding: 10upx 20upx;
		box-sizing: border-box;
	}

	.goods-price {
		margin-right: 20upx;
	}

	.goods-attention .price-text {
		font-size: 58upx;
	}

	/* .goods-message {} */

	.goods-message .line-price {
		text-decoration: line-through;
		margin-bottom: 5upx;
	}

	.goods-message .in-tag {
		background-color: #fff;
		color: #ec3467;
		border-radius: 12upx;
		padding: 1upx 12upx;
		margin-right: 10upx;
	}

	/* 拼团玩法 */

	.rule-nav {
		padding: 24upx;
		font-size: 29upx;
	}

	.rule-nav .rule-simple {
		margin-top: 35upx;
		color: #737373;
	}

	.rule-nav .i-number {
		width: 60upx;
		height: 60upx;
		border-radius: 50%;
		margin-bottom: 15upx;
		border: 1upx dashed #c0c0c0;
	}

	/* 进行中的团购 */

	.corwd {
		padding: 15upx 0upx;
		display: flex;
		height: 100upx;
		line-height: 1;
		justify-content: space-between;
		border-bottom: 1upx solid #eee;
	}

	.corwd:last-child {
		border-bottom: none;
	}

	.corwd_people {
		width: 40%;
		display: flex;
		align-items: center;
		box-sizing: border-box;
	}

	.corwd_people .corwd_people_images {
		margin-right: 12upx;
		width: 80upx;
		height: 80upx;
		border-radius: 50%;
		border: 2upx solid #eee;
	}

	.corwd_people text {
		font-size: 28upx;
	}

	.corwd_time {
		display: flex;
		align-items: center;
		width: 60%;
	}

	.corwd_time_text {
		width: 60%;
		text-align: center;
	}

	.corwd_time_title {
		display: block;
	}

	.corwd_time_title text {
		color: red;
	}

	.corwd_time_number {
		display: block;
		margin-top: 15upx;
		font-size: 23upx;
	}

	.corwd_time button {
		padding: 0upx 28upx;
		line-height: 55upx;
		text-align: center;
		font-size: 26upx;
		border-radius: 40upx;
		color: #fff;
		background: linear-gradient(to right, #fa1e8c 0, #fc1e56 100%);
		border: none;
	}

	.corwd_time button:after {
		content: none;
		border: none;
	}

	/* 弹窗 */
	.pop {
		visibility: hidden
	}

	.pop--show {
		visibility: visible
	}

	.pop__mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 14;
		background: rgba(0, 0, 0, .5);
		display: none
	}

	.pop__mask--hide {
		background: 0 0
	}

	.pop__container {
		position: fixed;
		left: 50%;
		top: 50%;
		-webkit-transform: translate3d(-50%, -50%, 0);
		transform: translate3d(-50%, -50%, 0);
		-webkit-transform-origin: center;
		transform-origin: center;
		-webkit-transition: all .2s ease;
		transition: all .2s ease;
		z-index: 15;
		opacity: 0
	}

	.pop--show .pop__container {
		opacity: 1
	}

	.pop--show .pop__mask {
		display: block
	}

	.pop--left .pop__container {
		left: 0;
		top: 50%;
		-webkit-transform: translate3d(-100%, -50%, 0);
		transform: translate3d(-100%, -50%, 0)
	}

	.pop--show.pop--left .pop__container {
		-webkit-transform: translate3d(0, -50%, 0);
		transform: translate3d(0, -50%, 0)
	}

	.pop--right .pop__container {
		right: 0;
		top: 50%;
		left: auto;
		-webkit-transform: translate3d(100%, -50%, 0);
		transform: translate3d(100%, -50%, 0)
	}

	.pop--show.pop--right .pop__container {
		-webkit-transform: translate3d(0, -50%, 0);
		transform: translate3d(0, -50%, 0)
	}

	.pop--bottom .pop__container {
		top: auto;
		left: 50%;
		/* bottom: 10%; */
		-webkit-transform: translate3d(-50%, 100%, 0);
		transform: translate3d(-50%, 100%, 0)
	}

	.pop--show.pop--bottom .pop__container {
		-webkit-transform: translate3d(-50%, 0, 0);
		transform: translate3d(-50%, 0, 0)
	}

	.pop--top .pop__container {
		top: 0;
		left: 50%;
		-webkit-transform: translate3d(-50%, -100%, 0);
		transform: translate3d(-50%, -100%, 0)
	}

	.pop--show.pop--top .pop__container {
		-webkit-transform: translate3d(-50%, 0, 0);
		transform: translate3d(-50%, 0, 0)
	}
	.pop_querenshop{
		bottom:0;
		bottom:0;
	}
</style>
